<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >

      <el-form-item label="时间" prop="checkInfoTime">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
        >重置</el-button
        >
        <el-button type="success" icon="el-icon-refresh" size="mini" @click="handleExport"
        >导出</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="deviceCorrosionInfoList"
    >
      <el-table-column label="设备id" align="center" prop="devId" ></el-table-column>
      <el-table-column label="计算时间" align="center" width="180" prop="updataTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updataTime, "{y}-{m}-{d} {h}:{i}:{s}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="腐蚀速率" align="center" prop="corrosionRate"></el-table-column>
      <el-table-column label="腐蚀模式" align="center" prop="corrosionMode"></el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page-sizes="[50, 100, 200]"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  getDevDetailInfoByCondition,
} from "@/api/devicedata/deviceCorrosion";

export default {
  name: "CorrosionData",
  data() {
    return {
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备数据
      deviceCorrosionInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
      },
      // 表单参数
      form: {},
      allVersion:[]
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询设备版本列表 */
    getList() {
      this.loading = true;
      getDevDetailInfoByCondition(this.addDateRange(this.queryParams, this.dateRange)).then((response) => {
        this.deviceCorrosionInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
       this.addDateRange(this.queryParams, this.dateRange);
       this.download('deviceDataInfo/exportCorrosionList', {
         ...this.queryParams
       }, `Corrosion_${new Date().getTime()}.xlsx`)
    },
  },
};
</script>
